package com.king.hpeproject.exception;

import com.king.hpeproject.constant.BusinessExceptionConstant;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

@EqualsAndHashCode(callSuper = true)
@Data
@Getter
public class BusinessException extends RuntimeException {
    /**
     * 状态码
     */
    private final int statusCode;

    /**
     * 业务错误码
     */
    private final String code;

    /**
     * 错误信息
     */
    private final String message;

    public BusinessException(BusinessExceptionConstant constant) {
        super(constant.getErrMsg());
        this.statusCode = constant.getStatusCode();
        this.code = constant.getErrCode();
        this.message = constant.getErrMsg();
    }

    public BusinessException(BusinessExceptionConstant constant, Object... elements) {
        super(String.format(constant.getErrMsg(),elements));
        String errMsg = String.format(constant.getErrMsg(),elements);
        this.statusCode = constant.getStatusCode();
        this.code = constant.getErrCode();
        this.message = errMsg;
    }
}